<?php

class BeersController extends ApplicationController
{
    protected $layout = 'public';
    
    public function index()
    {
        $this->beers = Beer::$objects->order_by('-created_on')->limit(20);
    }
    
    public function view()
    {
        //$this->beer = Beer::$objects->get_or_404($this->params['id']);
        $this->beer = Beer::$objects->get_by_slug_and_nom('eki', 'Eki');
    }
    
    public function add()
    {
        if ($this->request->is_post()) {
            $this->beer = new Beer($this->params['new_beer']);
            if ($this->beer->save()) {
                $this->redirect_to(array('action' => 'view', 'id' => $this->beer->id));
                return;
            }
        } else {
            $this->beer = new Beer();
        }
        $this->form = new SFormBuilder('new_beer', $this->beer);
    }
}

?>
